function navAllfunc1() {
  let navOrder = localStorage.getItem("navOrder") || 0;
  if (navOrder !== null && !isNaN(navOrder)) {
    setTimeout(() => {
      navUrlClick(navOrder);
    }, 100);
  }
  const navContainer = document.getElementById("nav-container");
  navContainer.innerHTML = navString1;
  const nav = document.querySelector(".nav");
  const navItems = document.querySelectorAll(".navItem");
  nav.addEventListener("click", (e) => {
    navOrder = e.target.id;
    navUrlClick(navOrder);
    localStorage.setItem("navOrder", navOrder);
    window.location.href = `./index${navOrder}.html`;
  });
  goodsClickData(); //商品分类 点击函数
  if (navItems.length <= 0) return;
  function navUrlClick(num) {
    if (num === null || isNaN(num)) {
      return;
    }
    navItems.forEach((item) => {
      item.classList.remove("active");
    });
    navItems[num].classList.add("active");
  }
}
// 产品列表分类
function goodsFn(data) {
  // 生成卡片
  const cardContainer = document.getElementById("cardContainer");
  data.forEach((item) => {
    const card = document.createElement("div");
    card.className = "card";
    card.innerHTML = `
           <img src="${item.img}" alt="${item.name}" class="card-img">
           <div class="card-text">${item.name}</div>
       `;
    cardContainer.appendChild(card);
  });
}
// 点击分类
function goodsClickData() {
  const navItems = document.querySelectorAll(".goods-sort");
  let value = 3;
  navItems.forEach((item) => {
    item.addEventListener("click", (e) => {
      const dataValue = e.target.getAttribute("data-value");
      value = +dataValue;
      if (dataValue === "1") {
        localStorage.setItem(`myCookie`, value);
      } else if (dataValue === "2") {
        localStorage.setItem(`myCookie`, value);
      } else if (dataValue === "3") {
        localStorage.setItem(`myCookie`, value);
      }
    });
  });
}
